﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dev.Control;
using SfcorpDLL.biz;
using SfcorpDLL.ety;
using GT.ORM;
using DevExpress.XtraSplashScreen;
using TT.Common;

namespace Sfcorp.form
{
    public partial class frmAccountDMT : BaseFormDev
    {
        bizAccountDMT bzAccountDMT;
        string gridHeard = string.Empty;

        public frmAccountDMT()
        {
            InitializeComponent();
        }

        private void frmAccountDMT_Load(object sender, EventArgs e)
        {
            this.splashScreenManager1 = new SplashScreenManager(this, typeof(global::Sfcorp.form.frmPleaseWaitMe), true, true);
            splitContainer.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1;

            bzAccountDMT = new bizAccountDMT(global.basSysPara);

            //核对列表
            //ggcAccountDMT.ClearColumns = false;
            ggcAccountDMT.GridView = this.gridView2;
            ggcAccountDMT.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click;
            ggcAccountDMT.FixColumns = "BILL_NO,ORIGINAL_BILL_NO,WORK_WAY_NAM,FEE_SUMMNY,FEE_CNTR_F_CY,LOC_AMOUNT,MATCH_FEE_AMOUNT_BOOL";
            gridHeard = string.Format("[CLIENT_COD;客户代码],[CLIENT_NAME;客户名称],[MONTH_ID;帐单月份],[BILL_CONFIRM_DT;码头确帐时间],[RECORD_DT;办单日期],[WORK_WAY_NAM;作业方式],[SERVICE_NO;服务单],[PREBAL_ID;预结号],[BILL_NO;海运提单号],[ORIGINAL_BILL_NO;原始提单号],[CARGO_NAM;货名],[C_SHIP_NAM;船名],[VOYAGE;航次],[TO_PORT_TIM;船到港时间],[LEAV_PORT_TIM;船离港时间],[CONTRACT_NO;委托号],[I_E_NAM;进出口],[TRANS_COUNTER;含中转数],[S20E_COUNTER;20\'E],[S20F_COUNTER;20\'F],[S40E_COUNTER;40\'E],[S40F_COUNTER;40\'F],[S45E_COUNTER;45\'E],[S45F_COUNTER;45\'F],[SOTHERE_COUNTER;其他柜型E],[SOTHERF_COUNTER;其他柜型F],[DANG_COUNTER;含危],[FEE_SUMMNY;港口费用合计],[FEE_SHIP_WORK;装卸船费],[FEE_FRUNK_WRAPIG;包干费],[FEE_SET_SEAL;加封费],[FEE_WORK_COST;工本费],[FEE_CNTR_E_CY;吉箱堆存费],[FEE_CNTR_F_CY;重箱堆存费],[FEE_OTHER;其他费用],[FEE_RETURN;退费金额],[RE_MARK;备注],[MATCH_CONTRACT_ID;是否匹配],[JCONTRACT_NO;货代单号],[SEA_BILL_NO;本地提单1],[AGENT_BILL_NO;本地提单2],[AVG_SIM_PERCENT1;相似度1%],[AVG_SIM_PERCENT2;相似度2%],[DOWNLOAD_TIM;下载时间],[CNTRS;本地箱数],[LOC_AMOUNT;自系统合计],[MATCH_FEE_AMOUNT_BOOL;金额匹配{0}CHECKBOX]", new string[] { stringProcess.Separator_Symbol });
            ggcAccountDMT.ColumnsMappingCreate(gridHeard);
            //ggcAccountDMT.GridView.OptionsBehavior.Editable = false;//网格不能编辑
            this.winUtil.LoadGridLayout(ggcAccountDMT);
            //计费单
            ggcBilling.GridView = this.gridView1;
            ggcBilling.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click;
            string sMapingCols = "CUSTOMER_NAME,ITEM_DESC,IO_FLAG_DESC,CASH_FLAG_DESC,UNIT_DESC,PRICE,QTY ,AMOUNT,INVOICE_NO,CHRG_DESC2,CHRG_DESC3,CHRG_DESC4,CHRG_DESC5,CHRG_FLT20,CHRG_DESC22  ,CHRG_DESC23,CHRG_FLT24,CHRG_DESC26";
            string sMapingHeaderTxt = "客户         ,费目     ,收支        ,交现金        ,单位     ,单价 ,数量,合计  ,收据编号  ,货代公司  ,进出口    ,结算方式  ,作业方式  ,业务单号  ,合作方       ,办单人     ,箱号      ,货物名称";
            ggcBilling.ColumnsMappingCreate(sMapingCols.Replace(" ", ""), sMapingHeaderTxt.Replace(" ", ""));
            this.winUtil.LoadGridLayout(ggcBilling); 
            //gridView2.Columns["ORIGINAL_BILL_NO"].Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left;
            //BILL_NO;海运提单号],[ORIGINAL_BILL_NO  FEE_SUMMNY   本系统合计  LightCyan   CNTRS PaleGreen
            ggcAccountDMT.ColumnBackColor =
                string.Format("BILL_NO,ORIGINAL_BILL_NO,WORK_WAY_NAM:{0};FEE_SUMMNY:{1};LOC_AMOUNT:{2}",
                new string[] { SystemColors.ButtonFace.ToArgb().ToString(), Color.Lavender.ToArgb().ToString(), Color.LightCyan.ToArgb().ToString() });
        }

        private void btnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Refresh();
        }

        public override void Refresh()
        {
            string addColumns = string.Empty;
            etyDmtCustomFblSummary ey = new etyDmtCustomFblSummary();
            //IList<etyDmtCustomFblSummary> ilSum = bzAccountDMT.GetDmtCustomFblSum(ey);
            DataTable dt = bzAccountDMT.GetDmtCustomFblSum(ey,ref addColumns);
            ggcAccountDMT.ColumnsMappingCreate(gridHeard + "," + addColumns);
            srcBinding.DataSource = dt;
            ggcAccountDMT.AutoColumnWidth();
            ggcAccountDMT.GridView.ClearSelection();
            base.Refresh();
        }

        private void ggcAccountDMT_DoubleClick(object sender, EventArgs e)
        {
            string contract_no = string.Empty;
            DataRowView dr = srcBinding.Current as DataRowView;
            if (dr == null)
                return;
            try { splashScreenManager1.ShowWaitForm(); }
            catch { }
            contract_no = dr.Row["JCONTRACT_NO"].ToString();
            MainForm mainForm = this.MdiParent as MainForm;
            DevExpress.XtraBars.Docking2010.Views.BaseDocument document = null;
            Sfcorp.form.frmAgyBns frmBns;
            if (mainForm.Documents.TryGetValue("Bns", out document))
            {
                frmBns = document.Form as Sfcorp.form.frmAgyBns;
                frmBns.Close();
            }
            frmBns = new Sfcorp.form.frmAgyBns();
            frmBns.ContractNo = contract_no;
            frmBns.MOD_ID = "barBns";
            frmBns.MdiParent = this.MdiParent;
            frmBns.Show();
            try{ splashScreenManager1.CloseWaitForm();  } catch { }
        }

        private void barViewPrice_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (splitContainer.PanelVisibility == DevExpress.XtraEditors.SplitPanelVisibility.Both)
            {
                barViewPrice.Caption = "显示费用";
                splitContainer.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1;
            }
            else
            {
                barViewPrice.Caption = "隐藏费用";
                splitContainer.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Both;
            }
        }

        private void ggcAccountDMT_Click(object sender, EventArgs e)
        {
            if (splitContainer.PanelVisibility == DevExpress.XtraEditors.SplitPanelVisibility.Both)
            {
                DataRowView dr = srcBinding.Current as DataRowView;
                if (dr == null)
                    return;
                etyChargeDtl ey = new etyChargeDtl();
                ey.CHRG_FLT20 = dr.Row["JCONTRACT_NO"].ToString();
                if (string.IsNullOrEmpty(ey.CHRG_FLT20))
                    return;
                try { splashScreenManager1.ShowWaitForm(); }
                catch { }
                IList<etyChargeDtl> ilCharge = new List<etyChargeDtl>();
                ilCharge = bzAccountDMT.GetBillResult(ey);
                ggcBilling.DataSource = ilCharge;
                try{ splashScreenManager1.CloseWaitForm();  } catch { }
            }
        }
    }
}
